﻿using System.Collections;
using UnityEngine;
using UnityEngine.UI;
using UniRx;

public class GameMenuPanel : UIPanelBase
{
    [SerializeField]
    private Button m_ResumeButton, m_SaveGameButton, m_SettingButton, m_MainMenuButton, m_QuitButton;

    protected override void OnInit()
    {
        CommandManager.FindStream("ui_game_menu").Subscribe(_ => OnShortcut()).AddTo(this);

        m_ResumeButton.onClick.AddListener(OnResumeButton);
        m_SaveGameButton.onClick.AddListener(OnSaveGameButton);
        m_SettingButton.onClick.AddListener(OnSettingButton);
        m_MainMenuButton.onClick.AddListener(OnMainMenuButton);
        m_QuitButton.onClick.AddListener(OnQuitButton);
    }

    protected override void OnShow()
    {
        Time.timeScale = 0;
    }

    protected override void OnHide()
    {
        Time.timeScale = 1;
    }

    private void OnShortcut()
    {
        Switch();
    }

    private void OnResumeButton()
    {
        Hide();
    }

    private void OnSaveGameButton()
    {

    }

    private void OnSettingButton()
    {

    }

    private void OnMainMenuButton()
    {
        SceneOrganizer.instance.GetPlayerSpawner().Despawn();
        GameManager.instance.LoadMainMenu();
        Hide();
    }

    private void OnQuitButton()
    {
        GameManager.instance.QuitGame();
    }
}